﻿Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DAO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General
Imports DevComponents.DotNetBar

Public Class frmQuyen
    Private m_QuyenCtrl As New QuyenCtrl()
    Public Sub New()
        InitializeComponent()
        DataService.OpenConnection()
    End Sub

    Private Sub frmQuyen_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        m_QuyenCtrl.HienThi(DGVQuyen, BindingNavigatorQuyen)
    End Sub

    Private Sub bindingNavigatorAddNewItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorAddNewItem.Click
        If DGVQuyen.RowCount = 0 Then
            BindingNavigatorQuyen.Enabled = True
        End If
        Dim m_Row As DataRow = m_QuyenCtrl.ThemDongMoi()
        m_Row("MaQuyen") = ""
        m_Row("TenQuyen") = ""
        m_QuyenCtrl.ThemMoi(m_Row)
        BindingNavigatorQuyen.BindingSource.MoveLast()

    End Sub

    Public Function KiemTraTruocKhiLuu(str As [String]) As [Boolean]
        For Each row As DataGridViewRow In DGVQuyen.Rows
            If row.Cells(str).Value IsNot Nothing Then
                Dim m_Str As [String] = row.Cells(str).Value.ToString()
                If m_Str = "" Then
                    MessageBoxEx.Show("Giá trị của ô không được rỗng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    Private Sub bindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorSaveItem.Click
        bindingNavigatorPositionItem.Focus()
        m_QuyenCtrl.LuuQuyen()
        MessageBoxEx.Show("Đã lưu thành công!", "Hoàn Thành", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub


    Private Sub bindingNavigatorDeleteItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorDeleteItem.Click
        If DGVQuyen.RowCount = 0 Then
            bindingNavigatorDeleteItem.Enabled = False

        ElseIf MessageBox.Show("Bạn có chắc chắn xóa dòng này không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            BindingNavigatorQuyen.BindingSource.RemoveCurrent()
        End If

    End Sub

    Private Sub bindingNavigatorCloseItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorCloseItem.Click
        Me.Close()
    End Sub
End Class